/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.cs.index.BrowseTerm;
/*    */ import com.zimbra.cs.index.DomainBrowseTerm;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.Mailbox.BrowseBy;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.io.IOException;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class Browse
/*    */   extends MailDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 40 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 41 */     Mailbox mbox = getRequestedMailbox(zsc);
/*    */     
/* 43 */     String browseBy = request.getAttribute("browseBy");
/* 44 */     Mailbox.BrowseBy parsedBrowseBy = Mailbox.BrowseBy.valueOf(browseBy.toLowerCase());
/* 45 */     String regex = request.getAttribute("regex", "").toLowerCase();
/* 46 */     int max = (int)request.getAttributeLong("maxToReturn", 0L);
/*    */     List<BrowseTerm> terms;
/*    */     try
/*    */     {
/* 50 */       terms = mbox.browse(getOperationContext(zsc, context), parsedBrowseBy, regex, max);
/*    */     } catch (IOException e) {
/* 52 */       throw ServiceException.FAILURE("Failed to browse terms", e);
/*    */     }
/*    */     
/* 55 */     Element response = zsc.createElement(MailConstants.BROWSE_RESPONSE);
/*    */     
/* 57 */     for (BrowseTerm term : terms) {
/* 58 */       if ((term instanceof DomainBrowseTerm)) {
/* 59 */         DomainBrowseTerm domain = (DomainBrowseTerm)term;
/* 60 */         Element e = response.addElement("bd").setText(domain.getText());
/* 61 */         String flags = domain.getHeaderFlags();
/* 62 */         if (!flags.isEmpty()) {
/* 63 */           e.addAttribute("h", flags);
/*    */         }
/* 65 */         e.addAttribute("freq", domain.getFreq());
/*    */       } else {
/* 67 */         Element e = response.addElement("bd").setText(term.getText());
/* 68 */         e.addAttribute("freq", term.getFreq());
/*    */       }
/*    */     }
/* 71 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/Browse.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */